﻿using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using ST.Torch.WebApi.Core.Entities.System;
using ST.Torch.WebApi.Core.Entities.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;


namespace ST.Torch.WebApi.Application.Utils.Services
{
    public class FormDataService : IFormDataService, ITransient
    {
        private readonly IRepository<FormData> _FormDataRepository;

        public FormDataService(IRepository<FormData> FormDataRepository)
        {
            _FormDataRepository = FormDataRepository;
        }

        public IRepository<FormData> GetRepository()
        {
            return _FormDataRepository;
        }
        #region curd
        public void Insert(FormData entity)
        {
            _FormDataRepository.Insert(entity);
        }
        public async Task InsertAsync(FormData entity, string[] Includes = null)
        {
            await _FormDataRepository.InsertAsync(entity);
        }
        public void Update(FormData entity, string[] Includes = null)
        {
            if (Includes == null)
                _FormDataRepository.Update(entity);
            else
                _FormDataRepository.UpdateInclude(entity, Includes);

        }
        public async Task UpdateAsync(FormData entity, string[] Includes = null)
        {
            if (Includes == null)
                await _FormDataRepository.UpdateAsync(entity);
            else
                await _FormDataRepository.UpdateIncludeAsync(entity, Includes);
        }
        public void Delete(FormData entity, bool IsSoft = false)
        {
            
                _FormDataRepository.Delete(entity);
            

        }
        public async Task DeleteAsync(FormData entity, bool IsSoft = false)
        {
            
                await _FormDataRepository.DeleteAsync(entity);
            

        }
        public bool Any(Expression<Func<FormData, bool>> predicate)
        {
            return _FormDataRepository.Any(predicate);
        }
        public async Task<bool> AnyAsync(Expression<Func<FormData, bool>> predicate)
        {
            return await _FormDataRepository.AnyAsync(predicate);
        }
        public FormData Single(Expression<Func<FormData, bool>> predicate, bool tracking = false)
        {
            return _FormDataRepository.SingleOrDefault(predicate, tracking);

        }
        public async Task<FormData> SingleAsync(Expression<Func<FormData, bool>> predicate, bool tracking = false)
        {
      
                return await _FormDataRepository.SingleOrDefaultAsync(predicate, tracking);

           

        }
        public List<FormData> Query(Expression<Func<FormData, bool>> predicate, bool tracking = false)
        {
            return _FormDataRepository.AsQueryable(tracking).Where(predicate).OrderByDescending(u => u.CreateTime).ToList();
        }
        public async Task<List<FormData>> QueryAsync(Expression<Func<FormData, bool>> predicate, bool tracking = false)
        {

               return await _FormDataRepository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToListAsync();
         
        }

        public PagedList<FormData> QueryPage(Expression<Func<FormData, bool>> predicate, PageReq page, bool tracking = false)
        {
            return _FormDataRepository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToPagedList(page.page, page.limit);
        }
        public async Task<PagedList<FormData>> QueryPageAsync(Expression<Func<FormData, bool>> predicate, PageReq page, bool tracking = false)
        {
            return await _FormDataRepository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToPagedListAsync(page.page, page.limit);
        }




        #endregion




    }
}
